<?php


/*
 * Filename: calendar.php
 * Auhor: trungt
 * Created on Jul 24, 2008 5:06:20 PM
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
require_once (JPATH_COMPONENT . DS . 'utils' . DS . 'jbs_calendar.php');

class JBSControllerCalendar extends JController {
	function display() {
		JRequest :: setVar('view', 'calendar');
		$model = $this->getModel('calendar');

		$month = JRequest :: getVar('month');
		$year = JRequest :: getVar('year');
		$day = 1;
		if (empty ($month) || empty ($year)) {
			$year = date('Y');
			$month = date('m');
			//			echo $year .'-'. $month;
			//		exit;
		}
		$calendar = new JBSCalendar;
		// First, create an array of month names, January through December
		$myMonths = array (
			JText::_('January'),
			JText::_('February'),
			JText::_('March'),
			JText::_('April'),
			JText::_('May'),
			JText::_('June'),
			JText::_('July'),
			JText::_('August'),
			JText::_('September'),
			JText::_('October'),
			JText::_('November'),
			JText::_('December')
		);
		// Then an array of day names, starting with Sunday
		$myDays = array (
			JText::_('SUN'),
			JText::_('MON'),
			JText::_('TUE'),
			JText::_('WED'),
			JText::_('THU'),
			JText::_('FRI'),
			JText::_('SAT')
		);
		$calendar->setMonthNames($myMonths);
		$calendar->setDayNames($myDays);
		$calendar->setStartDay(1);

		$displayMode = JRequest::getVar('display');	//Which type of calendar should be displayed ? (By Week, or Month)
		$displayCalendar = JRequest::getVar('items');	//What calendar should be displayed (Assets or Avents)

		switch ($displayCalendar) {
			case 'assets':		//Display Calendar of Assets
				switch($displayMode){
					case 'week':	//Render Week Calendar
						//Pass assets list to JBSCalendar object
						$calendar->setData($model->getDataForWeek($displayCalendar, $year, $month, 1));
						JRequest :: setVar('calendar', $calendar->renderWeek($month, $year, 1));
						break;
					default:	//Render Month Calendar
						//Pass events list to JBSCalendar object
						$calendar->setData($model->getDataForMonth($displayCalendar, $year, $month));
						JRequest :: setVar('calendar', $calendar->renderMonth($month, $year));
				}
				break;

			default:	//Display Calendar of Events
				switch($displayMode){
					case 'week':	//Render Week Calendar
						//Pass assets list to JBSCalendar object
						$calendar->setData($model->getDataForWeek('events', $year, $month, 1));
						JRequest :: setVar('calendar', $calendar->renderWeek($month, $year, 1));
						break;
					default:	//Render Month Calendar
						//Pass events list to JBSCalendar object
						$calendar->setData($model->getDataForMonth('events', $year, $month));
						JRequest :: setVar('calendar', $calendar->renderMonth($month, $year));
				}
		}

//		if($render = 'week')
//		JRequest :: setVar('calendar', $calendar->renderWeek($month, $year, 2));

		parent :: display();
	}
}
?>
